﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MvcShop.Models.ViewDataModels
{
    public class NewsViewData:ViewDataBase
    {
        #region ==== Property =====
        public int PageIndex { get; set; }
        public int Count { get; set; }
        public int Total { get; set; }
        public string KeyWord { get; set; }

        public News News { get; set; }
        public IEnumerable<News> Newss { get; set; }

        public IEnumerable<NewsList> NewsList { get; set; }
        #endregion

        #region ==== Methods ====
        public NewsViewData WithPageIndex(int pageIndex)
        {
            this.PageIndex = pageIndex;
            return this;
        }

        public NewsViewData WithCount(int count)
        {
            this.Count = count;
            return this;
        }

        public NewsViewData WithTotal(int pageSize)
        {
            this.Total = Math.Max((this.Count + pageSize - 1) / pageSize, 1); ;
            return this;
        }

        public NewsViewData WithKeyWord(string keyWord)
        {
            this.KeyWord = keyWord;
            return this;
        }

        public NewsViewData WithNews(News news)
        {
            this.News = news;
            return this;
        }

        public NewsViewData WithNewss(IEnumerable<News> newss)
        {
            this.Newss = newss;
            return this;
        }

        public NewsViewData WithNewsList(IEnumerable<NewsList> newsList)
        {
            this.NewsList = newsList;
            return this;
        }
        #endregion
    }

    public static class NewsView 
    {
        public static NewsViewData Data { get { return new NewsViewData(); } }
    }
}
